package com.example.demo.bean;

/**
 * @desc: <br/>
 * @author: Jingbo Hu<br/>
 * @time：2021年01⽉25⽇<br/>
 * @version：v1.0.0<br>
 */
public class BeanCopy {

    public static void main(String[] args) throws Exception {
        // 直接赋值
//        Fruit fruit1 = new Fruit("苹果");
//        Fruit fruit2 = fruit1;
//
//        fruit1.setName("香蕉");
//
//        System.out.println(fruit1);
//        System.out.println(fruit2);
//        System.out.println(fruit1.getName());
//        System.out.println(fruit2.getName());

        // 浅拷贝
//        Fruit fruit3 = new Fruit("苹果");
//        Fruit clone = fruit3.clone();
//
//        fruit3.setName("香蕉");
//
//        System.out.println(fruit3);
//        System.out.println(clone);
//        System.out.println(fruit3.getName());
//        System.out.println(clone.getName());
//
//        System.out.println("=======================");
//
//        System.out.println(Fruit.value);
//        Fruit.value = "world";
//        System.out.println(Fruit.value);

        // 深拷贝
        System.out.println("=======================");
        Person person = new Person(15, "zhangsan", new Address("四川", "天府二街"));

        Person clonePerson = (Person) person.deepClone();

        System.out.println(person);
        System.out.println(clonePerson);

        System.out.println(person.display());
        System.out.println(clonePerson.display());

        clonePerson.setName("wangwu");
        clonePerson.setAge(20);
        Address address = clonePerson.getAddress();
        address.setProvince("江西");
        address.setStreet("天府四街");
        System.out.println(clonePerson.display());
        System.out.println(person.display());
    }
}
